package com.wu.print1;

import java.util.Arrays;

/**
 * 打印从1到n的最大整数
 *
 * @author lynn
 * @date 2020/7/27 - 21:13
 */
public class Solution {

    public static void print1ToMaxOfNDigits(int n) {
        if (n <= 0) {
            return;
        }
        int[] nums = new int[n];
        for (int i = 0; i < 10; i++) {
            nums[0] = i;
            recursive(nums, n, 0);
        }
    }

    private static void recursive(int[] nums, int length, int index) {
        if (index == length - 1) {
            printNum(nums);
            return;
        }
        for (int i = 0; i < 10; i++) {
            nums[index + 1] = i;
            recursive(nums, length, index + 1);
        }
    }

    private static void printNum(int[] nums) {
        int index = 0;
        while (index < nums.length){
            if (nums[index] == 0) {
                index++;
            }else {
                break;
            }
        }
        StringBuilder builder = new StringBuilder();
        for (int i = index; i < nums.length; i++) {
            builder.append(nums[i]);
        }
        System.out.println(builder.toString());
    }

    public static void main(String[] args) {
        print1ToMaxOfNDigits(3);
    }
}
